package main

import "fmt"

func printSlice(s []int) {
	fmt.Printf("%v,len=%d,cap=%d\n", s, len(s), cap(s))
}

func main() {
	//var s []int

	//for i := 0; i < 100; i++ {
	//	printSlice(s)
	//	s = append(s, 2*i+1)
	//}
	//fmt.Println(s)
	fmt.Println("Created Slice")
	s1 := []int{2, 4, 6, 8}
	// 如果需要指定一个可变数组，但不知道值，go叫切片，可以如下声明
	s2 := make([]int, 16)
	// 要求初始化10个数据要存储，但数组长度为32
	s3 := make([]int, 10, 32)
	printSlice(s2)
	printSlice(s3)

	fmt.Println("Copying slice")
	copy(s2, s1)
	printSlice(s2)

	//删除任意位置
	fmt.Println("Deleting elements from slice")
	s2 = append(s2[:3], s2[4:]...)
	printSlice(s2)

	//删除头
	fmt.Println("Popping from front")
	front := s2[0]
	s2 = s2[1:]
	fmt.Println(front)
	printSlice(s2)
	//删除尾
	fmt.Println("Popping from back")
	tail := s2[len(s2)-1]
	s2 = s2[:len(s2)-1]
	fmt.Println(tail)
	printSlice(s2)
}
